using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SQLDAL;
using System.Data.SqlClient;

/// <summary>
/// Summary description for BookingTableDetailsBll
/// </summary>
public class BookingTableDetailsBll
{
	public BookingTableDetailsBll()
	{
		//
		// TODO: Add constructor logic here
		//
    }

    #region Fields
    string sp_AddTable = "sp_BookingTableDetails_AddTableInBookingTable";
    string sp_DeleteTable = "sp_BookingTableDetails_DeleteTable";
    string sp_ListAvailableTable = "sp_BookingTableDetails_ListTableAvailableByDateOfRestaurant";
    string sp_ListTable = " sp_BookingTableDetails_ListTableOfTableBooking";
    string sp_Total = "sp_BookingTableDetails_TotalByBooking";
    string sp_TotalDepositPay = "sp_BookingTableDetails_TotalDepositByBooking";
    string sp_UpdateTableBooking = "sp_BookingTableDetails_UpdateTableBooking";
    #endregion

    #region Add table in booking table
    public int AddTableInBookingTable(BookingTableDetailsInfo bookingTableDetailsInfo)
    {
        SqlParameter[] parms = { 
            new SqlParameter("@bookingDetailsID", SqlDbType.BigInt,8),
            new SqlParameter("@bookingID", SqlDbType.VarChar, 5),
            new SqlParameter("@tableID", SqlDbType.VarChar, 10),
            new SqlParameter("@dateBooking", SqlDbType.DateTime, 8),
            new SqlParameter("@dateUsingTable", SqlDbType.DateTime, 8),
            new SqlParameter("@timeUsing", SqlDbType.VarChar, 8),

        };
        parms[0].Value = bookingTableDetailsInfo.BookingDetailsID;
        parms[1].Value = bookingTableDetailsInfo.BookingID;
        parms[2].Value = bookingTableDetailsInfo.TableID;
        parms[3].Value = bookingTableDetailsInfo.DateBooking;
        parms[3].Value = bookingTableDetailsInfo.DateUsingTable;
        parms[3].Value = bookingTableDetailsInfo.TimeUsing;

        int result = SQLHelper.ExecuteNonQuery(SQLHelper.CONN_STRING, CommandType.StoredProcedure,
                                sp_AddTable, parms);
        return result;
    }
    #endregion

    #region Delete a table from table booking    
    public int DeleteTableFromTableBooking(BookingTableDetailsInfo bookingTableDetailsInfo)
    {
        SqlParameter[] parms = { 
            new SqlParameter("@bookingID", SqlDbType.VarChar, 5),
            new SqlParameter("@tableID", SqlDbType.VarChar, 10)
        };
        parms[0].Value = bookingTableDetailsInfo.BookingID;
        parms[1].Value = bookingTableDetailsInfo.TableID;

        int result = SQLHelper.ExecuteNonQuery(SQLHelper.CONN_STRING, CommandType.StoredProcedure,
                                sp_DeleteTable, parms);
        return result;

    }
#endregion

    #region List table available of restaurant by date  
    public SqlDataReader ListTableAvailableByDateOfRestaurant(
        BookingTableDetailsInfo bookingTableDetailsInfo, RestaurantInfo resInfo)
    {
         SqlParameter[] parms = { 
            new SqlParameter("@dateUsingTable", SqlDbType.DateTime, 8),
            new SqlParameter("@timeUsing", SqlDbType.VarChar, 8),
            new SqlParameter("@resID", SqlDbType.VarChar, 10)
        };
        parms[0].Value = bookingTableDetailsInfo.DateUsingTable;
        parms[1].Value = bookingTableDetailsInfo.TimeUsing;
        parms[2].Value = resInfo.ResID;

        return SQLHelper.ExecuteReader(SQLHelper.CONN_STRING, CommandType.StoredProcedure,
                                              sp_ListAvailableTable, parms);
    }
    #endregion

    #region List table of table booking    
    public SqlDataReader ListTableOfTableBooking(BookingTableDetailsInfo bookingTableDetailsInfo)
    {
        SqlParameter[] parms = { 
            new SqlParameter("@bookingID", SqlDbType.VarChar, 5)
        };
        parms[0].Value = bookingTableDetailsInfo.BookingID;
        return SQLHelper.ExecuteReader(SQLHelper.CONN_STRING, CommandType.StoredProcedure,
                                              sp_ListTable, parms);
    }
#endregion

    #region Total by booking    
    public SqlDataReader TotalByBooking(BookingTableDetailsInfo bookingTableDetailsInfo)
    {
        SqlParameter[] parms = {
            new SqlParameter("@bookingID", SqlDbType.VarChar, 5)
        };
        parms[0].Value = bookingTableDetailsInfo.BookingID;

        return SQLHelper.ExecuteReader(SQLHelper.CONN_STRING, CommandType.StoredProcedure,
                            sp_Total, parms);
    }
    #endregion

    #region Total deposit which a table booking have to pay    
    public SqlDataReader TotalDepositPay(BookingTableDetailsInfo bookingTableDetailsInfo)
    {
        SqlParameter[] parms = { 
            new SqlParameter("@bookingID", SqlDbType.VarChar, 5)
        };
        parms[0].Value = bookingTableDetailsInfo.BookingID;
        return SQLHelper.ExecuteReader(SQLHelper.CONN_STRING, CommandType.StoredProcedure,
                                              sp_TotalDepositPay, parms);
    }
    #endregion

    #region Update Table booking details
    public int UpdateTableBookingDetails(BookingTableDetailsInfo bookingTableDetailsInfo)
    {
        SqlParameter[] parms = { 
            new SqlParameter("@bookingDetailsID", SqlDbType.BigInt,8),
            new SqlParameter("@bookingID", SqlDbType.VarChar, 5),
            new SqlParameter("@tableID", SqlDbType.VarChar, 10),
            new SqlParameter("@dateBooking", SqlDbType.DateTime, 8),
            new SqlParameter("@dateUsingTable", SqlDbType.DateTime, 8),
            new SqlParameter("@timeUsing", SqlDbType.VarChar, 8),

        };
        parms[0].Value = bookingTableDetailsInfo.BookingDetailsID;
        parms[1].Value = bookingTableDetailsInfo.BookingID;
        parms[2].Value = bookingTableDetailsInfo.TableID;
        parms[3].Value = bookingTableDetailsInfo.DateBooking;
        parms[3].Value = bookingTableDetailsInfo.DateUsingTable;
        parms[3].Value = bookingTableDetailsInfo.TimeUsing;

        int result = SQLHelper.ExecuteNonQuery(SQLHelper.CONN_STRING, CommandType.StoredProcedure,
                                sp_UpdateTableBooking, parms);
        return result;
    }
    #endregion

    #region Cancel booking Table
    public SqlDataReader CancelBookingTable(BookingTableDetailsInfo info)
    {
        SqlParameter[] cmdParms = {
            new SqlParameter("@bookingID", SqlDbType.VarChar , 5)
        };
        cmdParms[0].Value = info.BookingID;
        return SQLHelper.ExecuteReader(SQLHelper.CONN_STRING, CommandType.StoredProcedure,
                                              "sp_BookingTableDetails_CancelBookingTable", cmdParms);
    }
    #endregion
}
